use crate::cp_cargo::driver::{
    cargo_motor, pick_motor,
    sensor::{
        is_cargo_motor_origin, is_compr_checked, is_cy_bottom_checked, is_cy_extern_checked,
        is_cy_inner_checked, is_cy_top_checked, is_loc2_checked, is_pick_motor_origin,
        is_rotation_button_click,
    },
};
use proto_bytes::ProtoEncode2;

const VERSION: u16 = 0x10;

pub fn collect() -> impl ProtoEncode2 {
    let cy_inner = is_cy_inner_checked();
    let cy_extern = is_cy_extern_checked();
    let cy_top = is_cy_top_checked();
    let cy_bottom = is_cy_bottom_checked();
    let pick_origin = is_pick_motor_origin();
    let compr = is_compr_checked();
    let cargo_btn = is_rotation_button_click();
    let cargo_origin = is_cargo_motor_origin();
    let loc2 = is_loc2_checked();
    let pick_alm = pick_motor::is_alm();
    let cargo_alm = cargo_motor::is_alm();
    let bit_sensor = ((cy_inner as u16) << 0)
        | ((cy_extern as u16) << 1)
        | ((cy_top as u16) << 2)
        | ((cy_bottom as u16) << 3)
        | ((pick_origin as u16) << 4)
        | ((compr as u16) << 5)
        | ((cargo_btn as u16) << 6)
        | ((cargo_origin as u16) << 7)
        | ((loc2 as u16) << 8)
        | ((pick_alm as u16) << 9)
        | ((cargo_alm as u16) << 10);

    (VERSION, bit_sensor)
}
